﻿
using System;
using System.IO;
using NUnit.Framework;
using RenewalProjects.Libraries.ParamGate.Attributes;
using RenewalProjects.Libraries.ParamGate.Exceptions;

namespace RenewalProjects.Libraries.ParamGate.Tests
{
	[TestFixture]
	public class FilesystemParameterAttributeFixture
	{
		#region Test Methods

		[Test]
		public void Filesystem_Parameter_Has_Valid_File_Path_But_May_Not_Exist()
		{
			FilesystemParameterAttribute attribute = new FilesystemParameterAttribute();
			attribute.VerifyExists = false;
			attribute.IsDirectory = false;
			attribute.ValidateParameter(null, "c:\\temp\\someFile.txt");
		}

		[Test]
		public void Filesystem_Parameter_Has_Valid_Directory_Path_But_May_Not_Exist()
		{
			FilesystemParameterAttribute attribute = new FilesystemParameterAttribute();
			attribute.VerifyExists = false;
			attribute.IsDirectory = true;
			attribute.ValidateParameter(null, "c:\\temp\\");
		}

		[Test]
		[ExpectedException(typeof(ArgumentException))]
		public void Filesystem_Parameter_Has_Invalid_Path()
		{
			FilesystemParameterAttribute attribute = new FilesystemParameterAttribute();
			attribute.IsDirectory = true;
			attribute.ValidateParameter(null, "some garbage path\0");
		}

		[Test]
		[ExpectedException(typeof(ArgumentException))]
		public void Filesystem_Parameter_Has_Invalid_FileName()
		{
			FilesystemParameterAttribute attribute = new FilesystemParameterAttribute();
			attribute.IsDirectory = false;
			attribute.ValidateParameter(null, "some path\\invalid?filename");
		}

		[Test]
		public void Filesystem_Parameter_Has_Valid_File_Path_And_Must_Exist()
		{
			FilesystemParameterAttribute attribute = new FilesystemParameterAttribute();
			attribute.VerifyExists = true;
			attribute.IsDirectory = false;
			attribute.ValidateParameter(null, Environment.SystemDirectory + "\\notepad.exe");
		}

		[Test]
		public void Filesystem_Parameter_Has_Valid_Directory_Path_And_Must_Exist()
		{
			FilesystemParameterAttribute attribute = new FilesystemParameterAttribute();
			attribute.VerifyExists = true;
			attribute.IsDirectory = true;
			attribute.ValidateParameter(null, Environment.SystemDirectory);
		}

		[Test]
		[ExpectedException(typeof(FileNotFoundException))]
		public void Filesystem_Parameter_Has_Valid_File_Path_And_Does_Not_Exist()
		{
			FilesystemParameterAttribute attribute = new FilesystemParameterAttribute();
			attribute.VerifyExists = true;
			attribute.IsDirectory = false;
			attribute.ValidateParameter(null, "c:\\some random dir\\you may not find it\\mysticalfile.what");
		}

		[Test]
		[ExpectedException(typeof(DirectoryNotFoundException))]
		public void Filesystem_Parameter_Has_Valid_Directory_Path_And_Does_Not_Exist()
		{
			FilesystemParameterAttribute attribute = new FilesystemParameterAttribute();
			attribute.VerifyExists = true;
			attribute.IsDirectory = true;
			attribute.ValidateParameter(null, "c:\\some random dir\\you may not find it\\");
		}

		[Test]
		[ExpectedException(typeof(ParameterValidationException))]
		public void Filesystem_File_Parameter_Has_Been_Passed_A_Non_String_Value()
		{
			FilesystemParameterAttribute attribute = new FilesystemParameterAttribute();
			attribute.IsDirectory = false;
			attribute.ValidateParameter(null, 111);
		}

		[Test]
		[ExpectedException(typeof(ParameterValidationException))]
		public void Filesystem_Directory_Parameter_Has_Been_Passed_A_Non_String_Value()
		{
			FilesystemParameterAttribute attribute = new FilesystemParameterAttribute();
			attribute.IsDirectory = true;
			attribute.ValidateParameter(null, 111);
		}

		#endregion
	}
}
